home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 13288 / 13288.xpi / content / sidebar.js < prev    next >
Text File  |  2010-01-24  |  2KB  |  64 lines

  1. var stmSBar = {
  2.  
  3.     onLoad: function(){
  4.         this.register();
  5.     },
  6.  
  7.     onUnLoad: function(){
  8.         this.unregister();
  9.     },
  10.  
  11.     patchSidebarURLOpen: function(pref_value) {
  12.         switch (pref_value) {
  13.             case true:  // Open URL in new tab
  14.                 eval("PlacesUIUtils.openNodeWithEvent = " + PlacesUIUtils.openNodeWithEvent.toString().replace(
  15.                     'this.openNodeIn(aNode, whereToOpenLink(aEvent));',
  16.                     'this.openNodeIn(aNode, stmC.onTabSwitch("", whereToOpenLink(aEvent)));'
  17.                 ));
  18.                 break;
  19.             case false:  // Original way to open
  20.                 eval("PlacesUIUtils.openNodeWithEvent = " + PlacesUIUtils.openNodeWithEvent.toString().replace(
  21.                     'this.openNodeIn(aNode, stmC.onTabSwitch("", whereToOpenLink(aEvent)));',
  22.                     'this.openNodeIn(aNode, whereToOpenLink(aEvent));'
  23.                 ));
  24.                 break;
  25.             default:  // Error
  26.                 alert("unknown error: swich to default!");
  27.                 break;
  28.         }            
  29.     },
  30.  
  31.     register: function() {
  32.         var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  33.         this._branch = prefService.getBranch("extensions.stm.");
  34.         this._branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
  35.         this._branch.addObserver("", this, false);
  36.         this._branch.getChildList("", {}).forEach(function(name){
  37.                                                       stmSBar.observe(null, "nsPref:changed", name); 
  38.                                                   });
  39.     },
  40.  
  41.     unregister: function() {
  42.         if(!this._branch) return;
  43.         this._branch.removeObserver("", this);
  44.     },
  45.  
  46.     observe: function(aSubject, aTopic, aData) {
  47.         if(aTopic != "nsPref:changed") return;
  48.         switch (aData) {
  49.           case "openBHSInNewTab":
  50.               var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  51.               this.patchSidebarURLOpen(prefs.getBoolPref("extensions.stm.openBHSInNewTab"));
  52.               break;
  53.         }
  54.     }
  55.  
  56. } //var end
  57.  
  58. window.addEventListener("load", function(e) { stmSBar.onLoad(); }, false);
  59. window.addEventListener("unload", function(e) { stmSBar.onUnLoad(); }, false);
  60.  
  61.  
  62.  
  63.  
  64.